package com.nf.health.app.activity.my.pay;

import android.os.Bundle;
import android.view.View;

import com.nf.health.app.R;
import com.nf.health.app.activity.global.BaseActivity;
import com.nf.health.app.adapter.ScannerHistoryAdapter;
import com.nf.health.app.customview.DragListView;
import com.nf.health.app.customview.EmptyView;
import com.nf.health.app.models.ScannerHistoryBean;
import com.nf.health.app.utils.ViewUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/5/8/008.
 * 支付历史记录
 */

public class ScannerPayHistoryActivity extends BaseActivity {

    int page = 1, pagesize = 20;
    ScannerHistoryAdapter scannerHistoryAdapter;
    List<ScannerHistoryBean> list;
//    @Bind(R.id.tv_no_data)
   // RelativeLayout tvNoData;
    private List<ScannerHistoryBean> contentList = new ArrayList<ScannerHistoryBean>();
    @Bind(R.id.scanner_listview)
    DragListView scannerListview;
    private EmptyView emptyView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitleBar(R.layout.titlebar_base);
        setContent(R.layout.activity_history_scanner_pay);
        ButterKnife.bind(this);
        ViewUtil.setText(this, R.id.titlebar_title_tv, "账单详情");
        scannerListview.setRefreshableAndLoadMoreable(true, true);
        scannerListview.setOnRefreshAndLoadMoreListener(new DragListView.onRefreshAndLoadMoreListener() {

            @Override
            public void onRefresh() {
                page = 1;
                initData("refresh");
            }

            @Override
            public void onLoadMore() {
                page++;
                initData("more");
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        initData("refresh");
    }

    private void initData(String flag) {
        provider.requestPayhistoryList(page + "", pagesize + "", flag);
    }


    @Override
    public void handleActionSuccess(String actionName, Object object) {
        super.handleActionSuccess(actionName, object);
        if ("refresh".equals(actionName)) {
            scannerListview.completeRefresh();
            list = (List<ScannerHistoryBean>) object;
            if(list.size()<1){
                EmptyView emptyView = new EmptyView(this);
                emptyView.mustCallInitWay(scannerListview);
                scannerListview.setEmptyView(emptyView.setOnRefreshData(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        initData("refresh");
                    }
                }));
            }else{
                scannerListview.setVisibility(View.VISIBLE);
            }
            contentList.clear();
            contentList.addAll(list);
            scannerHistoryAdapter = new ScannerHistoryAdapter(this, contentList);
            scannerListview.setAdapter(scannerHistoryAdapter);
        } else if ("more".equals(actionName)) {
            scannerListview.completeLoadMore();
            list = (List<ScannerHistoryBean>) object;

            if (list.size() == 0) {
                showToast("没有更多数据");
            } else {
                contentList.addAll(list);
                scannerHistoryAdapter.notifyDataSetChanged();
            }
        }
    }
}
